﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Planer.Model
{
    public enum OperationStatusType {OK, ERROR}

    public class ModelResult
    {
        protected OperationStatusType status = OperationStatusType.OK;

        public OperationStatusType Status
        {
            get { return status; }
        }
        protected List<string> errors = new List<string>();

        public List<string> Errors
        {
            get { return errors; }
        }

        public string FirstError
        {
            get
            {
                if (errors.Count > 0)
                {
                    return errors[0];
                }
                return "";
            }
        }

        public string ShowAllMessages
        {
            get
            {
                StringBuilder strBuilder = new StringBuilder();
                foreach (string error in errors)
                {
                    strBuilder.AppendLine(error);
                }
                return strBuilder.ToString();
            }
        }

        public ModelResult(IEnumerable<string> errors)
        {
            if (errors != null && errors.Count<string>() > 0)
            {
                this.errors.AddRange(errors);
                status = OperationStatusType.ERROR;
            }
        }

        public ModelResult(string error)
        {
            if (errors != null && error != "")
            {
                this.errors.Add(error);
                status = OperationStatusType.ERROR;
            }
        }

        public ModelResult()
        {
        }
    }
}
